let express = require('express');
let router = express.Router();
/* GET home page. */


/**
 * 用户注册
 */
router.all('/bindRole', function (req, res, next) {
    global['bean'].RoleBindingPermissionService.addRolePermissionEntity(req.args).then(data => {
        res.json(res.wrap(20000, '绑定成功!', data));
    }).catch(e => {
        next(e);
    });
});

router.all('/bindRoles', function (req, res, next) {
    global['bean'].RoleBindingPermissionService.addBatchRolePermissionEntity(req.args).then(data => {
        res.json(res.wrap(20000, '批量绑定成功!', data));
    }).catch(e => {
        next(e);
    });
});
/**
 * 删除角色
 */
router.all('/removeRolePermission', function (req, res, next) {
    global['bean'].RoleBindingPermissionService.removeRolePermissionEntity(req.args).then(data => {
        res.json(res.wrap(20000, '移除成功!', data))
    }).catch(e => {
        next(e);
    });
});


/**
 * 更新角色
 */
router.all('/removeBatchRolePermission', function (req, res, next) {
    global['bean'].RoleBindingPermissionService.removeBatchRolePermissionEntity(req.args).then(data => {
        res.json(res.wrap(20000, '批量移除成功!', data))
    }).catch(e => {
        next(e);
    });
});

/**
 * 删除角色
 */
router.all('/listPermissionUnderRole', function (req, res, next) {
    global['bean'].RoleBindingPermissionService.listRolePermissionEntities(req.args.rid).then(data => {
        res.json(res.wrap(20000, '查询角色绑定权限表', data))
    }).catch(e=>{
        next(e)
    })
});

module.exports = router;
